package com.xzp.bams.server;

import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;

/**
 * @TODO
 * @Author xu
 * 2025/3/23
 */
public class ATMSever extends JFrame {
    RankPanel rankPanel;
    ServerPanel serverPanel;

    public ATMSever() {
        //设置窗体的基本信息
        this.setTitle("ATM");
        //设置关闭方式，关闭即退出
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //设置窗体的尺寸
        this.setSize(500, 600);
        //居中显示
        this.setLocationRelativeTo(getOwner());

        //初始化共同数据

        //实例化JPanel界面
        rankPanel = new RankPanel();
        serverPanel = new ServerPanel();

        //将JPanel添加至JFrame窗体容器中
        Container container = this.getContentPane();
        //设置容器为卡片式布局
        container.setLayout(new CardLayout());
        //默认显示第一个w
        container.add(serverPanel, "serverPanel");
        container.add(rankPanel, "rankPanel");

        //点击关闭服务器按钮，关闭服务
        //关闭服务，关闭窗体
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing (WindowEvent e){
                super.windowClosing(e);
                try {
                    serverPanel.ss.close();
                } catch (IOException ex) {
                    throw new RuntimeException(ex);
                }
                System.exit(0);
            }
        });
    }
//











    public static void main(String[] args) {
        new ATMSever().setVisible(true);
    }
}